/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef WISHMASTER_SINGLETON_H
#define WISHMASTER_SINGLETON_H

#include <QMessageBox>
#include <cassert>

namespace Wishmaster
{
	template <typename Type>
	class Singleton
	{
	public:
		Singleton()
		{
			m_instance = static_cast<Type*>(this);
		}

		virtual ~Singleton()
		{
			m_instance = 0;
		}

		static Type* instance()
		{
			return m_instance;
		}

	private:
		static Type* m_instance;
		// no need to implement them!
		Singleton(const Singleton<Type>&);
		Singleton<Type>& operator=(const Singleton<Type>& t);
	};

	// This should be here, otherwise compiler will complain about
	// unresolved externals
	template <typename Type> Type* Singleton<Type>::m_instance = 0;
}

#endif
